package gui;

import exceptions.RelationAlreadyInSetException;
import exceptions.RelationNotInSetException;
import gui.detail.DetailPanel;
import gui.sidebar.database.DatabaseSpecPanel;
import gui.sidebar.relations.RelationContainerPanel;
import gui.sidebar.SidebarContainerPanel;
import gui.sidebar.transactions.TransactionContainerPanel;

import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.event.ListSelectionListener;

import java.awt.*;
import java.awt.event.ActionListener;

/**
 * Created by IntelliJ IDEA.
 * User: Jason Ye
 * Date: 31/01/2012
 * Time: 18:25

 */
public class NeptuneContainerPanel extends JPanel {

    private RelationContainerPanel relationContainerPanel;
    private TransactionContainerPanel transactionContainerPanel;
    private DatabaseSpecPanel databaseSpecPanel;

    private SidebarContainerPanel sideBarContainerPanel;
    
    private DetailPanel detailPanel;

    public NeptuneContainerPanel() {
        
        
        this.relationContainerPanel = new RelationContainerPanel();
        this.transactionContainerPanel = new TransactionContainerPanel();
        this.databaseSpecPanel = new DatabaseSpecPanel();

        this.sideBarContainerPanel = new SidebarContainerPanel(relationContainerPanel,transactionContainerPanel,databaseSpecPanel);

        this.detailPanel = new DetailPanel();
        this.detailPanel.setBorder(new LineBorder(Color.black));


        setUpTopLevelLayout();
    }

    public void setUpTopLevelLayout() {

        this.setLayout(new BorderLayout());

        detailPanel.setSize(new Dimension(300, 400));

        // add sidebarcontainerpanel to the screen
        this.add(sideBarContainerPanel,BorderLayout.WEST);

        //set up and add detail panel
        this.add(detailPanel,BorderLayout.CENTER);

    }
    


    private void setUpDetailPanel(){

        detailPanel.setMinimumSize(new Dimension(800, 600));

    }


    public void addRelationSelectionListeners(ListSelectionListener listSelectionListener) {

        sideBarContainerPanel.addRelationSelectionListeners(listSelectionListener);

    }

    public void removeRelation() {
        sideBarContainerPanel.removeRelation();
    }

    public void addRemoveRelationButtonListener(ActionListener removeRelationButtonListener) {
        sideBarContainerPanel.addRemoveRelationButtonListener(removeRelationButtonListener);
    }

    public void addAddRelationButtonListener(ActionListener addRelationButtonListener) {
        sideBarContainerPanel.addAddRelationButtonListener(addRelationButtonListener);
    }

    public void addRelation(String s) throws RelationAlreadyInSetException {
        sideBarContainerPanel.addRelation(s);
    }

    public void renameRelation(String s, String s1) throws RelationNotInSetException, RelationAlreadyInSetException {
        sideBarContainerPanel.renameRelation(s,s1);
    }

    public String getCurrentlySelectedRelation() {
        return sideBarContainerPanel.getCurrentlySelectedRelation();
    }

    public void addRenameRelationButtonListener(ActionListener renameRelationButtonListener) {
        sideBarContainerPanel.addRenameRelationButtonListener(renameRelationButtonListener);
    }

    public void setSelectedRelation(String s) {
        sideBarContainerPanel.setSelectedRelation(s);
    }


    public void addDBSpecButtonListener(ActionListener specDialog) {
        sideBarContainerPanel.addDBSpecButtonListener(specDialog);
    }

    public void addEvaluateButtonListener(ActionListener evaluateButtonListener) {

        sideBarContainerPanel.addEvaluateButtonListener(evaluateButtonListener);
    }
}
